package com.topisv.tms.task;

import com.topisv.tms.service.stock.check.CheckPlanService;
import com.topisv.tms.service.task.ScheduledTaskService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 定时生成盘点计划
 *  Date          Author       Version       Description
 * ----------------------------------------------------------
 *  2015-7-10      CC            1.0           Create
 */
@Component
@Lazy(false)
public class CheckPlanCreateTask {
	private Logger log = LoggerFactory.getLogger(getClass());

	@Autowired
	private CheckPlanService checkPlanService;

	@Autowired
	private ScheduledTaskService scheduledTaskService;

	@Scheduled(cron = "0 0 7 * * *")
	public void execute() {
		try {
			try {
				scheduledTaskService.lock();
			} catch (Exception e) {
			}
			boolean rs = scheduledTaskService.check();
			if (rs) {
				log.info("check plan create begin.");
				checkPlanService.autoCreateCheckPlan();
			}
		} catch (Exception e) {
			log.error("auto create checkPlan error", e);
		}
	}
}